package com.cwvs.cat.bean;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;

public class ClubMember {
	
	public static final int ORDINARY = 0;
	public static final int CHIEF = 1;
	public static final int DEPUTY = 2;
	public int orgId;
	public int userId;
	public int memberType = ORDINARY;
	public String createdTime;
	public boolean recieve;
	public String name;
	public String order;
	public String avatar;
	
	
	public void fromJson(JSONArray json){
		orgId = json.optInt(0);
		userId = json.optInt(1);
		memberType = json.optInt(2);
		createdTime = json.optString(3); 
		if(0 == json.optInt(4)){
			recieve = false;
		}else{
			recieve = true;
		}
		name = json.optString(5);
		order = json.optString(6);
		avatar =  json.optString(7);
	}
	
	public JSONObject toJson(){
		JSONObject json = new JSONObject();
		try {
			json.put("org_id", orgId);
			json.put("uid", userId);
			json.put("admin", memberType);
			json.put("recieve",recieve);
			json.put("nickname", name);
			json.put("orderbyfirst",order);
			json.put("avatar",avatar);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return json;
	}
	
	public static ClubMember createFromJson(JSONArray json) {
		ClubMember msgSystem = new ClubMember();
		msgSystem.fromJson(json);
		return msgSystem;
	}	
}
